package org.rcloud.io.service.impl;

import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.ShootMapper;
import org.rcloud.io.model.Shoot;
import org.rcloud.io.service.ShootService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/3/28.
 */
@Service(value = "ShootService")
public class ShootServiceImpl implements ShootService {
    @Autowired
    private ShootMapper shootMapper;

    @Override
    public ResultVo deleteByPrimaryKey(String id) {

        try {
            shootMapper.deleteByPrimaryKey(id);
            return ResultVo.setOK(null);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo insert(Shoot record) {
        if (record.equals("")||record == null){
            return ResultVo.setError("传入的数据为空！");
        }else {
            try {
                int i =shootMapper.insert(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }

        }
    }

    @Override
    public ResultVo insertSelective(Shoot record) {
        if (record.equals("")||record == null){
            return ResultVo.setError("传入数据为空");
        }else {
            try {
                int i = shootMapper.insertSelective(record);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public ResultVo selectById(Shoot record) {
        try {
            Shoot shoot = shootMapper.selectById(record);
            return ResultVo.setOK(shoot);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public PageVo<Shoot> selectByPrimaryKey(Shoot record) {
        try {
            List<Shoot> list = shootMapper.selectByPrimaryKey(record);
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo updateByPrimaryKeySelective(Shoot record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                shootMapper.updateByPrimaryKeySelective(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }


    @Override
    public ResultVo updateByPrimaryKey(Shoot record) {
        if (record.equals("")||record == null) {
            return ResultVo.setError("传入的数据为空！");
        } else {
            try {
                shootMapper.updateByPrimaryKey(record);
                return ResultVo.setOK(null);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }
    }

    @Override
    public PageVo<Shoot> selectAll() {
        try {
            List<Shoot> list = shootMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

}
